package top.mczhengyi.xyblog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import top.mczhengyi.xyblog.entity.Reply;

import java.util.List;

@Mapper
public interface ReplyMapper extends BaseMapper<Reply> {
    // Get Reply By Id
    @Select("SELECT id, target, reply_id replyId, layer, content, username, email, avatar, create_time createTime, " +
            "anonymous, visible\n" +
            "FROM `b_reply`\n" +
            "WHERE target = #{id} AND visible = 1")
    @Results({
            @Result(column = "replyId", property = "reply", many =
                    @Many(select = "top.mczhengyi.xyblog.mapper.ReplyMapper.selectReplyById"))
    })
    List<Reply> getReplyByTargetId(int id);

    @Select("SELECT id, target, reply_id replyId, layer, content, username, email, avatar, create_time createTime, " +
            "anonymous, visible\n" +
            "FROM `b_reply`\n" +
            "WHERE id = #{id}")
   Reply selectReplyById(int id);

    @Select("SELECT id, target, reply_id replyId, layer, content, username, email, avatar, create_time createTime, " +
            "anonymous, visible\n" +
            "FROM `b_reply`")
    @Results({
            @Result(column = "target", property = "blog",
                    one = @One(select = "top.mczhengyi.xyblog.mapper.BlogMapper.selectBlogWithId"))
    })
    List<Reply> getAllReply();

    @Update("UPDATE `b_reply` SET visible = 1 WHERE id = #{id}")
    Integer applyComment(int id);
}
